package com.zygh.questionnairesurvey.util;

import org.apache.commons.lang.StringUtils;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class SpileUtil {

    /**
     * 获取需要删除的id
     *
     * @param str1 前端传入新的id字符串
     * @param str2 数据库已有需要被覆盖掉的字符串
     * @return String
     */
    public static String compare(String str1, String str2) {
        List<String> list1 = Arrays.asList(str1.split(","));
        List<String> list2 = Arrays.asList(str2.split(","));
        Set<String> set1 = new HashSet<>(list1);
        Set<String> set2 = new HashSet<>(list2);
        Set<String> common = new HashSet<>(set1);
        //获取两个集合的交集  common.retainAll(set2);
        //获取需要删除的id
        set2.removeAll(set1);
        Object[] array = set2.toArray();
        //String splitSet = StringUtils.join(array);
        String splitSetWithComma = StringUtils.join(array, ",");
        return splitSetWithComma;
    }

    public static void main(String[] args) {
        String str1 = "13,8,7,86,83,63,180,157";
        String str2 = "12,13";
        System.out.println(compare(str1, str2));
    }


}
